<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>获取当前时间</title>
	</head>
	<body>
		<h2 id="time"></h2>
		<script type="text/javascript">
			var time = document.getElementById('time');
			function nowNumTime(){
				var now = new Date();
				var year = now.getFullYear();
				var month = now.getMonth();
				var week = now.getDay();
				console.log(week);
				var hour = now.getHours();
				var minute =  now.getMinutes();
				var second = now.getSeconds();
				var d = now.getDate();
				var weeks = ['星期一','星期二','星期三','星期四','星期五','星期六','星期天'];
				var temp = ''+(hour > 12 ? hour-12:hour);
				if(hour == 0 ){
					temp = '12';
				}
				temp = temp+(minute < 10 ? ':0':":")+minute;
				temp = temp+(second < 10 ? ':0':":")+second
				temp = temp+(hour < 12 ? '-P.M':"-A.M");
				temp = temp+'--'+year+'年'+(month+1)+'月'+d+'日'+'--'+weeks[week-1];
				console.log(temp);
				time.innerHTML = '当前时间为：'+temp;
			}
			setInterval(nowNumTime,1000);
			
			
		</script>
	</body>
</html>
